package com.example.demo.producer;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.sql.SQLOutput;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;

/**
 * @Author xiao
 * @Date 2025/5/6 上午 10:11
 * @ClassName: ThreadDemo
 * @Desc:
 */
@Slf4j
public class ThreadDemo {
    public static void main(String[] args) throws IOException {
        log.info("主线程输出");
       new Thread(() -> {
            log.info("Thread异步调用线程输出");
        }).start();

       new Thread(new Runnable() {
           public void run() {
               log.info("Runnable异步调用线程输出");
           }
       }).start();

        CompletableFuture.supplyAsync(ThreadDemo::f1)
               .exceptionally(ex ->{
                    System.out.println("Handled exception: " + ex.getMessage());
                    return "方法异常"; // 提供默认值
                }) .thenAccept(log::info);

        //System.in.read();
    }


    public static String f1(){
        log.info(" f1执行了");
        int i = 1/0;
        return "f1执行完毕";
    }
}
